<template>
  <div class="parameterInfor flowCloumn h100">
    <div class="constentBttom flowWrap tab-switch h100">
      <div class="constentTree treeDiv">
        <customTree
          ref="equipTree"
          :draggable="false"
          :btnArr="btnArr"
          :nodeKey="nodeKey"
          :itemArrs="itemArrs"
          :expandNode="defaultNodeId"
          @handleClickTree="handleClickTree"
        ></customTree>
      </div>
      <div class="draggingBtn">
        <width-resize></width-resize>
      </div>
      <div class="constentmain tableDiv">
        <el-tabs ref="tabsBadge" v-model="activeName" type="card" class="h100">
          <el-tab-pane name="1">
            <span slot="label">基本信息</span>
            <div class="tabPaneContent h100" v-if="activeName == '1'">
              <equipmentManage
                :currentNode="currentNode"
                @updateTree="updateTree"
                @setBasicData="setBasicData"
                menuType="paramInfor"
              ></equipmentManage>
            </div>
          </el-tab-pane>
          <el-tab-pane name="2">
            <span slot="label">异动记录</span>
            <div class="tabPaneContent h100" v-if="activeName == '2'">
              <equipmentMove :currentNode="currentNode" @updateTree="updateTree" menuType="query"></equipmentMove>
            </div>
          </el-tab-pane>
           <el-tab-pane name="3">
            <span slot="label">缺陷记录</span>
            <div class="tabPaneContent h100" v-if="activeName == '3'">
              <defectOrder :currentNode="currentNode" @updateTree="updateTree" showType="query" :isEquipment="true"></defectOrder>
            </div>
          </el-tab-pane>
          <el-tab-pane name="4">
            <span slot="label">维护记录</span>
            <div class="tabPaneContent h100" v-if="activeName == '4'">
              <normalMaintenance
                :currentNode="currentNode"
                :isEquipment="true"
                @updateTree="updateTree"
                showType="query"
                ordeType="maintain"
              ></normalMaintenance>
            </div>
          </el-tab-pane>
          <el-tab-pane name="5">
            <span slot="label">检修记录</span>
            <div class="tabPaneContent h100" v-if="activeName == '5'">
              <normalMaintenance
                :currentNode="currentNode"
                :isEquipment="true"
                @updateTree="updateTree"
                showType="query"
                ordeType="repair"
              ></normalMaintenance>
            </div>
          </el-tab-pane>
          <el-tab-pane name="6">
            <span slot="label">试验记录</span>
            <div class="tabPaneContent h100" v-if="activeName == '6'">
              <normalMaintenance
                :currentNode="currentNode"
                :isEquipment="true"
                @updateTree="updateTree"
                showType="query"
                ordeType="experiment"
              ></normalMaintenance>
            </div>
          </el-tab-pane>
         
          <el-tab-pane name="7">
            <span slot="label">大修记录</span>
            <div class="tabPaneContent h100" v-if="activeName == '7'">
              <overhaul :currentNode="currentNode" @updateTree="updateTree" showType="query" :isEquipment="true"></overhaul>
            </div>
          </el-tab-pane>
          <el-tab-pane name="8">
            <span slot="label">巡视记录</span>
            <div class="tabPaneContent h100" v-if="activeName == '8'">
              <patrolOrder :currentNode="currentNode" @updateTree="updateTree" showType="query"></patrolOrder>
            </div>
          </el-tab-pane>
          <el-tab-pane name="9">
            <span slot="label">监测数据</span>
            <div class="tabPaneContent h100" v-if="activeName == '9'">
              <monitoringYC v-if="isYinChuan" :currentNode="currentNode"></monitoringYC>
              <monitoring v-else :currentNode="currentNode" />
            </div>
          </el-tab-pane>
          <el-tab-pane name="10">
            <span slot="label">专项记录</span>
            <div class="tabPaneContent h100" v-if="activeName == '10'">
              <specialParameter
                :currentNode="currentNode"
                @updateTree="updateTree"
                showType="query"
              ></specialParameter>
            </div>
          </el-tab-pane>
          <el-tab-pane name="11">
            <span slot="label">人工记录</span>
            <div class="tabPaneContent h100" v-if="activeName == '11'">
              <listTableNew v-bind="tableSetting" ref="klTable"></listTableNew>
            </div>
          </el-tab-pane>
          <el-tab-pane name="12">
            <span slot="label">图档资料</span>
            <div class="tabPaneContent h100" v-if="activeName == '12'">
              <libraryFiles :equipId="currentId" :equipName="currentNodeName" :fileFullPath="fileFullPath"></libraryFiles>
            </div>
          </el-tab-pane>
          <el-tab-pane name="13">
            <span slot="label">备品备件</span>
            <div class="tabPaneContent h100" v-if="activeName == '13'">
              <sparePartList :currentNode="currentNode" :pageType="pageType"></sparePartList>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>
<script>
import equipmentManage from "../equipmentManage/basicInfo";
import equipmentMove from "../equipmentMove/index";
import monitoring from "./monitoring";
import monitoringYC from "./monitoringYC"
import normalMaintenance from "@/views/orderManagement/normalMaintenance/index";
import defectOrder from "@/views/orderManagement/defectOrder/property/listTablePage";
import overhaul from "@/views/orderManagement/overhaul/index";
import patrolOrder from "@/views/orderManagement/patrolOrder/index";
import specialParameter from "@/views/specialManagement/specialParameter/index";
import sparePartList from "@/views/equipmentLedger/sparePart/parameterInfoList";
import libraryFiles from "./libraryFiles.vue";
import {
  getLeftUpperApi,
  getManualRecordApi,
  getEquipment
} from "@/api/equipmentLedger/equipmentManage";
// import customTree from "@/components/customTree/customTree";
import customTree from "../customTree";
import {
  getParentIdsApi, //获取某个节点的所有父节点
} from "@/api/equipmentLedger/equipmentManage";
export default {
  components: {
    equipmentManage,
    equipmentMove,
    customTree,
    normalMaintenance,
    defectOrder,
    patrolOrder,
    specialParameter,
    monitoring,
    monitoringYC,
    sparePartList,
    libraryFiles,
    overhaul,
  },
  data() {
    return {
      fileFullPath: '',
      userInfo: this.$store.getters.userInfo,
      hideBtn: true,
      activeName: "1",
      pageType: "parameterInfoIndex",
      haveRemark: true,
      itemArrs: [],
      btnArr: [],
      nodeKey: "id",
      currentNode: {},
      currentId:"",
      currentNodeName: '',
      defaultNodeId: "",
      //附件设置
      attachSetting: {
        businessId: "", //单据的ID
        businessType: "parameterInforImageFile"
      },
      tableSetting: {
        showCustomBtn: false,
        showFilterBtn: false,
        showPagination: false,
        searchObj: {
          searchMethod: (params, sortStr) => {
            this.getTableData(params, sortStr);
          },
          queryData: {
            page: 1,
            pageSize: 10
          },
          searchArr: [
            {
              type: "input",
              label: "参数名",
              model: "name"
            },
            {
              label: "记录时间",
              model: "updateTimes",
              type: "datetimerange"
            },
            {
              type: "user",
              label: "记录人",
              model: "updateByName",
              idsStr: "updateBy",
              placeholder: "请选择记录人",
              methods: val => {}
            }
          ]
        },
        actionList: [],
        column: [
          {
            label: "参数名",
            prop: "name"
          },
          {
            label: "参数值",
            prop: "value"
          },
          {
            label: "记录时间",
            prop: "updateTime"
          },
          {
            label: "记录人",
            prop: "updateByName"
          },
          {
            label: "巡视工单编号",
            prop: "orderCode",
            type: "textButton",
            method: (obj, index) => {
              this.goDetailPage(obj, "patrolOrderDetails", "details");
            }
          }
        ],
        //表格方法
        tableMethods: {
          //点击行的方法
          rowClick: val => {
            // this.gotoDetails(val);
          }
        }
      }
    };
  },
  watch: {
    activeName: {
      handler: function(val) {
        if (val == "11") {
          setTimeout(() => {
            this.updateData();
          }, 800);
        }
      }
    },
    currentNode: {
      handler: function(newVal, oldVal) {
        this.currentDevice = Object.assign({}, newVal);
        let queryData = Object.assign(this.tableSetting.searchObj.queryData, {
          equipId: newVal.id,
          equipName: newVal.name
        });
        this.tableSetting.searchObj.queryData = {};
        this.tableSetting.searchObj.queryData = queryData;
        setTimeout(() => {
          if (oldVal && this.activeName == "11") {
            //不是第一次
            this.updateData();
          }
        }, 0);
      },
      deep: true,
      immediate: true
    }
  },

  computed: {
    systemOrg() {
      return localStorage.getItem("currOrg");
    },
    isYinChuan() {
      return this.$store.getters.currentAppInfo.appCode == "EAM_YCSC";
    },
  },
  created() {},
  mounted() {
    this.init();
  },

  methods: {
    init() {
      let { equipId, equipName } = this.$route.query;
      //如果路由中带有设备信息，则要默认展示此设备相关的信息
      if (equipId) {
        this.defaultNodeId = equipId;
      }
    },
    updateData() {
      this.$refs.klTable.searchData();
    },
    //获取基本信息
    setBasicData(data){
      this.searchData = {
        collectionSearch:true,
        floor:data.floor
      }
    },
    getTableData(params, sortStr) {
      let form = { ...params };
      if (sortStr) {
        form.orders = sortStr;
      }
      getManualRecordApi(form)
        .then(res => {
          let data = res.data.list || [];
          let total = res.data.total || 0;
          this.$set(this.tableSetting, "tableData", data);
          this.$set(this.tableSetting, "totalNumber", total);
        })
        .catch(e => {
          this.$set(this.tableSetting, "tableData", []);
          this.$set(this.tableSetting, "totalNumber", 0);
        });
    },
    updateTree(type) {
      //当提交和保存时，type有值
      let node = null;
      if (type) {
        node = this.currentNode;
      }
      this.$refs.equipTree.updataData(node);
    },
    //点击树
    async handleClickTree(node) {
      this.currentNode = node;
      this.currentId = node.id;
      this.currentNodeName = node.name
      const { data } = await getParentIdsApi(this.currentId);
      this.fileFullPath = data.join("/") + "/" + this.currentId;
    },
    //跳转到详情页
    goDetailPage(row, router, type) {
      const { href } = this.$router.resolve({
        name: router,
        query: {
          id: row ? row.patrolId : "",
          pageType: type ? type : ""
        }
      });
      window.open(href, "_blank");
    }
  }
};
</script>
<style lang="less" scoped>
.parameterInfor {
  .constentmain {
    margin-left: 15px;
  }
  /deep/.el-tabs__content {
    height: calc(100% - 50px);
  }
  /deep/.el-tab-pane {
    height: 100%;
  }
}
.flowCloumn {
  display: flex;
  flex-flow: column nowrap;
}
.flowWrap {
  display: flex;
  flex-flow: wrap nowrap;
}
.el-tabs--border-card {
  box-shadow: none;
}
</style>